export const sourcecolumns = [
  {
    title: '实例id',
    dataIndex: 'instanceId',
    width: '80',
  },
  {
    title: '实例名称',
    dataIndex: 'instanceName',
    width: '80',
  },

  {
    title: '数据库IP',
    dataIndex: 'dbIp',
    width: '80',
  },
  {
    title: '数据库端口号',
    dataIndex: 'dbPort',
    width: '80',
  },

  {
    title: '数据库账号',
    dataIndex: 'dbUsername',
    width: '80',
  },
  {
    title: '是否被使用',
    dataIndex: 'isUsed',
    width: '80',
  },
  {
    title: '操作',
    dataIndex: 'action',
    width: '150',
  },
];
export const searchFormSchema = [
  {
    field: 'dbIp',
    label: '数据库IP',
    component: 'Input',
    required: false,
    colProps: {
      span: 6,
    },
    componentProps: {
      placeholder: '请输入数据库IP',
    },
  },
];
export const sourceSchema = [
  {
    field: 'instanceId',
    label: '实例ID',
    component: 'Input',
    required: true,
    componentProps: {
      placeholder: '请输入实例ID',
    },
  },
  {
    field: 'instanceName',
    label: '实例名称',
    component: 'Input',
    required: true,
    componentProps: {
      placeholder: '请输入实例名称',
    },
  },
  {
    field: 'dbIp',
    label: '数据库IP',
    component: 'Input',
    required: true,
    componentProps: {
      placeholder: '请输入数据库IP',
    },
  },
  {
    field: 'dbPort',
    label: '数据库端口号',
    component: 'Input',
    required: true,
    componentProps: {
      placeholder: '请输入数据库端口号',
    },
  },
  {
    field: 'dbUsername',
    label: '数据库账号',
    component: 'Input',
    required: true,
    componentProps: {
      placeholder: '请输入数据库账号',
    },
  },
  {
    field: 'dbPassword',
    label: '数据库密码',
    component: 'InputPassword',
    required: true,
    componentProps: {
      placeholder: '请输入数据库密码',
    },
  },
  {
    field: 'isUsed',
    label: '是否被使用',
    component: 'Switch',
    required: false,
    componentProps: {
      checkedChildren: '是',
      unCheckedChildren: '否',
      checkedValue: true,
      unCheckedValue: false,
      defaultChecked: false,
    },
  },
];
export const updateSourceSchema = [
  {
    field: 'instanceId',
    label: '实例ID',
    component: 'Input',
    required: true,
    componentProps: {
      placeholder: '请输入实例ID',
    },
  },
  {
    field: 'instanceName',
    label: '实例名称',
    component: 'Input',
    required: true,
    componentProps: {
      placeholder: '请输入实例名称',
    },
  },
  {
    field: 'dbIp',
    label: '数据库IP',
    component: 'Input',
    required: true,
    dynamicDisabled: true,
    componentProps: {
      placeholder: '请输入数据库IP',
    },
  },
  {
    field: 'dbPort',
    label: '数据库端口号',
    component: 'Input',
    required: true,
    dynamicDisabled: true,
    componentProps: {
      placeholder: '请输入数据库端口号',
    },
  },
  {
    field: 'dbUsername',
    label: '数据库账号',
    component: 'Input',
    required: true,
    dynamicDisabled: true,
    componentProps: {
      placeholder: '请输入数据库账号',
    },
  },
  {
    field: 'dbPassword',
    label: '数据库密码',
    component: 'InputPassword',
    required: true,
    dynamicDisabled: true,
    componentProps: {
      placeholder: '请输入数据库密码',
    },
  },
  {
    field: 'isUsed',
    label: '是否被使用',
    component: 'Switch',
    required: false,
    dynamicDisabled: true,
    componentProps: {
      checkedChildren: '是',
      unCheckedChildren: '否',
      checkedValue: true,
      unCheckedValue: false,
      defaultChecked: false,
    },
  },
];
const validateVolumeSize = (rule, value) => {
  if (value == undefined) {
    return Promise.reject(new Error('请输入磁盘大小'));
  } else if (value < 40 || value > 128000 || value % 10 !== 0) {
    return Promise.reject(new Error('磁盘大小取值范围：40~128000，必须为10的整数倍'));
  } else {
    return Promise.resolve();
  }
};

export const configRules = {
  datastoreVersion: [
    {
      trigger: 'change',
      required: true,
      message: '请选择数据库版本',
    },
  ],
  slaveCount: [
    {
      trigger: 'change',
      required: true,
      message: '请选择备节点个数',
    },
    {
      trigger: 'change',
      type: 'integer',
      message: '请选择正确的备节点个数',
    },
  ],
  volumeSize: [
    {
      trigger: 'change',
      required: true,
      validator: validateVolumeSize,
    },
  ],
  flavorRef: [
    {
      trigger: 'change',
      required: true,
      message: '请选择规格码',
    },
  ],

  volumeType: [
    {
      trigger: 'change',
      required: true,
      message: '请选择磁盘类型',
    },
  ],
};
export const pwdRule = [
  { required: true, message: '请输入密码' },
  {
    pattern: /[a-zA-Z\d!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]{8,18}/,
    message: '请输入密码长度为8-18位,包含大小写字母、数字和特殊字符4类至少3类',
  },
];
